﻿using CalligraphyEditor.CalligraphyData;
using CalligraphyEditor.ViewModel;
using DevExpress.Xpf.Grid;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CalligraphyEditor
{
    /// <summary>
    /// Interaction logic for DevStelePapers.xaml
    /// </summary>
    public partial class DevStelePapers : Page,IPage
    {
        private VMStelePapers _vm;

        public DevStelePapers(T_Author a)
        {
            InitializeComponent();
            _vm = new VMStelePapers(a);
            Gcl_StelePaper.DataContext = _vm.Cvs;
            Cmb_Style.ItemsSource = VMBaseData.Style;
            Cmb_Dynast.ItemsSource = VMBaseData.Dynast;
        }


        public bool Editable
        {
            get { return true; }
        }

        public string Path
        {
            get { return string.Empty; }
        }

        public void Add()
        {
            ChooseSteleOrPaper c = new ChooseSteleOrPaper();
            if (c.ShowDialog() == true)
            {
                _vm.Add(c.IsPaper);
            }
        }

        public void Delete()
        {
            _vm.Deleted();
        }

        public void Save()
        {
            _vm.Save();
        }

        private void view_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            Save();
        }

        private void Button_Click_AddPhoto(object sender, RoutedEventArgs e)
        {
            if (_vm.UploadPhoto())
            {
                Gcl_StelePaper.RefreshRow(Gcl_StelePaper.View.FocusedRowHandle);
            }
        }


        private void Button_Click_Browse(object sender, RoutedEventArgs e)
        {
            T_StelePaper stelePaper = _vm.Cvs.View.CurrentItem as T_StelePaper;
            NavigateToPageEventArgs arg = new NavigateToPageEventArgs();
            if (stelePaper.IsPaper == true)
            {
                DevPaperPhotos p = new DevPaperPhotos(stelePaper);
                arg.ToPage = p;
            }
            else
            {
                DevRubbings p = new DevRubbings(stelePaper);
                arg.ToPage = p;
            }
            NavigateToPage(this, arg);
        }

        public event EventHandler<NavigateToPageEventArgs> NavigateToPage;
    }
}
